package edu.sdufe.controller;

import edu.sdufe.entity.School;
import edu.sdufe.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("/api/schools")
public class SchoolController {
    private final SchoolService schoolService;

    @Autowired
    public SchoolController(SchoolService schoolService) {
        this.schoolService = schoolService;
    }

    @PostMapping
    public boolean createSchool(@RequestBody School school) {
        return schoolService.save(school);
    }

    @PutMapping
    public boolean updateSchool(@RequestBody School school) {
        return schoolService.update(school);
    }

    @DeleteMapping("/{id}")
    public boolean deleteSchool(@PathVariable Long id) {
        return schoolService.delete(id);
    }

    @GetMapping("/{id}")
    public School getSchoolById(@PathVariable Long id) {
        return schoolService.getById(id);
    }

    @GetMapping
    public List<School> getAllSchools() {
        return schoolService.getAll();
    }
}
